<template>
  <div id="side_nav">
    <ul>
      <li @click="toSeckill">秒杀专区</li>
      <li @click="toNiceGoods">特色优选</li>
      <li @click="toProduct">为你推荐</li>
      <li @click="toTop">&ensp;<i class="el-icon-caret-top"></i>&ensp; 顶部</li>
    </ul>
  </div>
</template>

<script>
export default {
  name: "SideNav",
  data() {
    return {
      distance: 0,
    };
  },
  mounted() {
    window.addEventListener("scroll", this.handleScroll);
  },
  methods: {
    handleScroll() {
      this.distance = document.documentElement.scrollTop;
      var nav = document.getElementById("side_nav");
      if (this.distance >= 700) {
        nav.style.top = "100px";
        nav.style.position = "fixed";
      } else {
        nav.style.top = "600px";
        nav.style.marginTop = "0px";
        nav.style.position = "absolute";
      }
    },
    toSeckill() {
      document.documentElement.scrollTop = 700;
    },
    toNiceGoods() {
      document.documentElement.scrollTop = 970;
    },
    toProduct() {
      document.documentElement.scrollTop = 1250;
    },
    toTop() {
      document.documentElement.scrollTop = 0;
    },
  },
  destroyed(){
    console.log(22222);
  },
  beforeDestroy() {
    window.removeEventListener("scroll", this.handleScroll);
  },
  
};
</script>

<style scoped>
#side_nav {
  width: 58px;
  height: 252px;
  font-size: 14px;
  background-color: #fff;
  position: absolute;
  margin-left: 250px;
  margin-top: -115px;
  box-shadow: 5px 5px 10px whitesmoke;
}
#side_nav ul {
  width: 58px;
  height: 252px;
  padding: 0;
  overflow: hidden;
}
#side_nav li {
  width: 38px;
  height: 38px;
  color: #333;
  margin: 20px auto;
  text-align: center;
  list-style: none;
}
#side_nav li::after {
  content: "";
  position: absolute;
  display: inline-block;
  width: 40px;
  height: 1px;
  margin-top: 25px;
  margin-left: -32px;
  background: linear-gradient(270deg, white, red, red, white);
}
#side_nav li:hover {
  color: red;
  cursor: pointer;
}
</style>